// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <ThreeSliceAttributes.h>
#include <DataNode.h>

// ****************************************************************************
// Method: ThreeSliceAttributes::ThreeSliceAttributes
//
// Purpose:
//   Init utility for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void ThreeSliceAttributes::Init()
{
    x = 0;
    y = 0;
    z = 0;
    interactive = true;

    ThreeSliceAttributes::SelectAll();
}

// ****************************************************************************
// Method: ThreeSliceAttributes::ThreeSliceAttributes
//
// Purpose:
//   Copy utility for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void ThreeSliceAttributes::Copy(const ThreeSliceAttributes &obj)
{
    x = obj.x;
    y = obj.y;
    z = obj.z;
    interactive = obj.interactive;

    ThreeSliceAttributes::SelectAll();
}

// Type map format string
const char *ThreeSliceAttributes::TypeMapFormatString = THREESLICEATTRIBUTES_TMFS;
const AttributeGroup::private_tmfs_t ThreeSliceAttributes::TmfsStruct = {THREESLICEATTRIBUTES_TMFS};


// ****************************************************************************
// Method: ThreeSliceAttributes::ThreeSliceAttributes
//
// Purpose:
//   Default constructor for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ThreeSliceAttributes::ThreeSliceAttributes() :
    AttributeSubject(ThreeSliceAttributes::TypeMapFormatString)
{
    ThreeSliceAttributes::Init();
}

// ****************************************************************************
// Method: ThreeSliceAttributes::ThreeSliceAttributes
//
// Purpose:
//   Constructor for the derived classes of ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ThreeSliceAttributes::ThreeSliceAttributes(private_tmfs_t tmfs) :
    AttributeSubject(tmfs.tmfs)
{
    ThreeSliceAttributes::Init();
}

// ****************************************************************************
// Method: ThreeSliceAttributes::ThreeSliceAttributes
//
// Purpose:
//   Copy constructor for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ThreeSliceAttributes::ThreeSliceAttributes(const ThreeSliceAttributes &obj) :
    AttributeSubject(ThreeSliceAttributes::TypeMapFormatString)
{
    ThreeSliceAttributes::Copy(obj);
}

// ****************************************************************************
// Method: ThreeSliceAttributes::ThreeSliceAttributes
//
// Purpose:
//   Copy constructor for derived classes of the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ThreeSliceAttributes::ThreeSliceAttributes(const ThreeSliceAttributes &obj, private_tmfs_t tmfs) :
    AttributeSubject(tmfs.tmfs)
{
    ThreeSliceAttributes::Copy(obj);
}

// ****************************************************************************
// Method: ThreeSliceAttributes::~ThreeSliceAttributes
//
// Purpose:
//   Destructor for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ThreeSliceAttributes::~ThreeSliceAttributes()
{
    // nothing here
}

// ****************************************************************************
// Method: ThreeSliceAttributes::operator =
//
// Purpose:
//   Assignment operator for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ThreeSliceAttributes&
ThreeSliceAttributes::operator = (const ThreeSliceAttributes &obj)
{
    if (this == &obj) return *this;

    ThreeSliceAttributes::Copy(obj);

    return *this;
}

// ****************************************************************************
// Method: ThreeSliceAttributes::operator ==
//
// Purpose:
//   Comparison operator == for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
ThreeSliceAttributes::operator == (const ThreeSliceAttributes &obj) const
{
    // Create the return value
    return ((x == obj.x) &&
            (y == obj.y) &&
            (z == obj.z) &&
            (interactive == obj.interactive));
}

// ****************************************************************************
// Method: ThreeSliceAttributes::operator !=
//
// Purpose:
//   Comparison operator != for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
ThreeSliceAttributes::operator != (const ThreeSliceAttributes &obj) const
{
    return !(this->operator == (obj));
}

// ****************************************************************************
// Method: ThreeSliceAttributes::TypeName
//
// Purpose:
//   Type name method for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

const std::string
ThreeSliceAttributes::TypeName() const
{
    return "ThreeSliceAttributes";
}

// ****************************************************************************
// Method: ThreeSliceAttributes::CopyAttributes
//
// Purpose:
//   CopyAttributes method for the ThreeSliceAttributes class.
//
// Programmer: Akira Haddox
// Creation:   Mon Jun 9 13:18:30 PST 2003
//
// Modifications:
//
// ****************************************************************************

bool
ThreeSliceAttributes::CopyAttributes(const AttributeGroup *atts)
{
    if(atts->TypeName() == "PointAttributes")
    {
        if (interactive)
        {
            const PointAttributes *tmp = (const PointAttributes *)atts;
            const double *xyz = tmp->GetPoint();
            SetX(xyz[0]);
            SetY(xyz[1]);
            SetZ(xyz[2]);
            return true;
        }
    }

    if(TypeName() != atts->TypeName())
        return false;

    // Call assignment operator.
    const ThreeSliceAttributes *tmp = (const ThreeSliceAttributes *)atts;
    *this = *tmp;

    return true;
}

// ****************************************************************************
// Method: ThreeSliceAttributes::CreateCompatible
//
// Purpose:
//   CreateCompatible method for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: Akira Haddox
// Creation:   Mon Jun 9 13:18:30 PST 2003
//
// Modifications:
//   Akira Haddox, Wed Jul  2 11:11:26 PDT 2003
//   Added PointAttributes.
//
// ****************************************************************************

AttributeSubject *
ThreeSliceAttributes::CreateCompatible(const std::string &tname) const
{
    AttributeSubject *retval = 0;
    if(TypeName() == tname)
        retval = new ThreeSliceAttributes(*this);
    if(tname == "PointAttributes" && interactive)
    {
        PointAttributes *p = new PointAttributes;
        double pt[3];
        pt[0] = GetX();
        pt[1] = GetY();
        pt[2] = GetZ();
        p->SetPoint(pt);
        retval = p;
    }

    return retval;
}

// ****************************************************************************
// Method: ThreeSliceAttributes::NewInstance
//
// Purpose:
//   NewInstance method for the ThreeSliceAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeSubject *
ThreeSliceAttributes::NewInstance(bool copy) const
{
    AttributeSubject *retval = 0;
    if(copy)
        retval = new ThreeSliceAttributes(*this);
    else
        retval = new ThreeSliceAttributes;

    return retval;
}

// ****************************************************************************
// Method: ThreeSliceAttributes::SelectAll
//
// Purpose:
//   Selects all attributes.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void
ThreeSliceAttributes::SelectAll()
{
    Select(ID_x,           (void *)&x);
    Select(ID_y,           (void *)&y);
    Select(ID_z,           (void *)&z);
    Select(ID_interactive, (void *)&interactive);
}

///////////////////////////////////////////////////////////////////////////////
// Persistence methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: ThreeSliceAttributes::CreateNode
//
// Purpose:
//   This method creates a DataNode representation of the object so it can be saved to a config file.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
ThreeSliceAttributes::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd)
{
    if(parentNode == 0)
        return false;

    ThreeSliceAttributes defaultObject;
    bool addToParent = false;
    // Create a node for ThreeSliceAttributes.
    DataNode *node = new DataNode("ThreeSliceAttributes");

    if(completeSave || !FieldsEqual(ID_x, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("x", x));
    }

    if(completeSave || !FieldsEqual(ID_y, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("y", y));
    }

    if(completeSave || !FieldsEqual(ID_z, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("z", z));
    }

    if(completeSave || !FieldsEqual(ID_interactive, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("interactive", interactive));
    }


    // Add the node to the parent node.
    if(addToParent || forceAdd)
        parentNode->AddNode(node);
    else
        delete node;

    return (addToParent || forceAdd);
}

// ****************************************************************************
// Method: ThreeSliceAttributes::SetFromNode
//
// Purpose:
//   This method sets attributes in this object from values in a DataNode representation of the object.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void
ThreeSliceAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("ThreeSliceAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("x")) != 0)
        SetX(node->AsDouble());
    if((node = searchNode->GetNode("y")) != 0)
        SetY(node->AsDouble());
    if((node = searchNode->GetNode("z")) != 0)
        SetZ(node->AsDouble());
    if((node = searchNode->GetNode("interactive")) != 0)
        SetInteractive(node->AsBool());
}

///////////////////////////////////////////////////////////////////////////////
// Set property methods
///////////////////////////////////////////////////////////////////////////////

void
ThreeSliceAttributes::SetX(double x_)
{
    x = x_;
    Select(ID_x, (void *)&x);
}

void
ThreeSliceAttributes::SetY(double y_)
{
    y = y_;
    Select(ID_y, (void *)&y);
}

void
ThreeSliceAttributes::SetZ(double z_)
{
    z = z_;
    Select(ID_z, (void *)&z);
}

void
ThreeSliceAttributes::SetInteractive(bool interactive_)
{
    interactive = interactive_;
    Select(ID_interactive, (void *)&interactive);
}

///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////

double
ThreeSliceAttributes::GetX() const
{
    return x;
}

double
ThreeSliceAttributes::GetY() const
{
    return y;
}

double
ThreeSliceAttributes::GetZ() const
{
    return z;
}

bool
ThreeSliceAttributes::GetInteractive() const
{
    return interactive;
}

///////////////////////////////////////////////////////////////////////////////
// Keyframing methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: ThreeSliceAttributes::GetFieldName
//
// Purpose:
//   This method returns the name of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

std::string
ThreeSliceAttributes::GetFieldName(int index) const
{
    switch (index)
    {
    case ID_x:           return "x";
    case ID_y:           return "y";
    case ID_z:           return "z";
    case ID_interactive: return "interactive";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: ThreeSliceAttributes::GetFieldType
//
// Purpose:
//   This method returns the type of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeGroup::FieldType
ThreeSliceAttributes::GetFieldType(int index) const
{
    switch (index)
    {
    case ID_x:           return FieldType_double;
    case ID_y:           return FieldType_double;
    case ID_z:           return FieldType_double;
    case ID_interactive: return FieldType_bool;
    default:  return FieldType_unknown;
    }
}

// ****************************************************************************
// Method: ThreeSliceAttributes::GetFieldTypeName
//
// Purpose:
//   This method returns the name of a field type given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

std::string
ThreeSliceAttributes::GetFieldTypeName(int index) const
{
    switch (index)
    {
    case ID_x:           return "double";
    case ID_y:           return "double";
    case ID_z:           return "double";
    case ID_interactive: return "bool";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: ThreeSliceAttributes::FieldsEqual
//
// Purpose:
//   This method compares two fields and return true if they are equal.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
ThreeSliceAttributes::FieldsEqual(int index_, const AttributeGroup *rhs) const
{
    const ThreeSliceAttributes &obj = *((const ThreeSliceAttributes*)rhs);
    bool retval = false;
    switch (index_)
    {
    case ID_x:
        {  // new scope
        retval = (x == obj.x);
        }
        break;
    case ID_y:
        {  // new scope
        retval = (y == obj.y);
        }
        break;
    case ID_z:
        {  // new scope
        retval = (z == obj.z);
        }
        break;
    case ID_interactive:
        {  // new scope
        retval = (interactive == obj.interactive);
        }
        break;
    default: retval = false;
    }

    return retval;
}

///////////////////////////////////////////////////////////////////////////////
// User-defined methods.
///////////////////////////////////////////////////////////////////////////////

